package com.hl.controller;

import com.hl.common.constant.Constants;
import com.hl.common.controller.BaseController;
import com.hl.common.domain.AjaxResult;
import com.hl.common.page.TableDataInfo;
import com.hl.domain.Type;
import com.hl.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 类型Controller
 *
 * @author Jimbo
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/type")
public class TypeController extends BaseController {
    @Autowired
    private ITypeService typeService;

    /**
     * 查询类型列表
     */
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(value = Constants.PAGE_NUM, required = false, defaultValue = Constants.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = Constants.PAGE_SIZE, required = false, defaultValue = Constants.PAGE_SIZE_DEFAULT) Integer pageSize,
                           Type type) {
        Map<String, Object> map = typeService.selectTypeList(pageNum, pageSize, type);
        return success(map);
    }

    /**
     * 获取类型详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(typeService.selectTypeById(id));
    }

    /**
     * 新增类型
     */
    @PostMapping
    public AjaxResult add(@RequestBody Type type) {
        return toAjax(typeService.insertType(type));
    }

    /**
     * 修改类型
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Type type) {
        return toAjax(typeService.updateType(type));
    }

    /**
     * 删除类型
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(typeService.deleteTypeByIds(ids));
    }
}
